﻿using AutoMapper;
using MediatR;
using S.Archives.Api.Application.Command;
using S.Archives.Infrstructre.InterFace;

namespace S.Archives.Api.Application.CommandHandlers
{
    public class WanderStateEditCommandHandler : IRequestHandler<WanderStateEditCommand, bool>
    {
        private readonly ISheepFileRepository sheepFileRepository;
        private readonly IMapper mapper;
        public WanderStateEditCommandHandler(ISheepFileRepository sheepFileRepository, IMapper mapper)
        {
            this.sheepFileRepository = sheepFileRepository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 修改流转状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<bool> Handle(WanderStateEditCommand request, CancellationToken cancellationToken)
        {
            var wander= sheepFileRepository.GetAll().FirstOrDefault(x=>x.EarTag==request.EarTag);
            wander.WanderReproductiveState = request.WanderReproductiveState;
            return  sheepFileRepository.Update(wander);
        }
    }
}
